package com.mc.music_web.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mc.music_web.entity.Admin;
import com.mc.music_web.mapper.AdminMapper;
import com.mc.music_web.services.AdminService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.*;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;
    public Admin login(Admin admin) {

        Admin admi=adminMapper.login(admin);

        return  admi;

    }

  /*  public PageInfo<Admin> selectAllList(int pageNum, int pageSize) {
        //过滤分页，设置当前页码，页显示条数
        PageHelper.startPage(pageNum,pageSize);

        List<Admin> list = adminMapper.selectAllList();
        //使用pageInfo包装数据，返回给控制器
        PageInfo<Admin> pageInfo = new PageInfo<Admin>(list);
        return pageInfo;
    }*/

    public int insert(Admin admin) {
        return adminMapper.insert(admin);
    }

    public int delteAdmin(Admin admin) {
        return adminMapper.delteAdmin(admin);
    }

    public int updateByPrimaryKey(Admin admin) {
        return adminMapper.updateByPrimaryKey(admin);
    }

    public PageInfo selectLimit(int pageNum) {
        PageHelper.startPage(pageNum,3);
        List<Admin> list = adminMapper.selectAllList();
        PageInfo<Admin> pageInfo = new PageInfo<Admin>(list);
        System.out.println("当前页码："+pageInfo.getPageNum());
        System.out.println("页面大小："+pageInfo.getPageSize());
        System.out.println("总记录数："+pageInfo.getTotal());
        System.out.println("是否有上一页："+pageInfo.isHasPreviousPage());
        System.out.println("是否有下一页："+pageInfo.isHasNextPage());
        System.out.println("总页面数："+pageInfo.getPages());
        return pageInfo;
    }

    public Admin selectByPrimaryKey(Integer adminId) {
        return adminMapper.selectByPrimaryKey(adminId);
    }

    public List<Admin> selectAllList() {
        return adminMapper.selectAllList();
    }

    public List<Admin> selectByChoose(String keyword) {
        return adminMapper.selectByChoose(keyword);
    }


}
